import React, { Component } from "react";
//引入react-redux包
import { connect } from "react-redux";
//引入store
import { add_cart_action } from "../../store/store";
class DetList extends Component {
    constructor() {
        super();
        this.state = {};
    }
    render() {
        let ind = this.props.match.params.index * 1;
        let list = this.props.location.state;
        return (
            <div className="detlist">
                {list[ind].children.map((item, index) => {
                    return (
                        <div key={item.id} className="detlist-item">
                            <div>
                                <img src={item.img} alt="" />
                            </div>
                            <div>
                                <p>{item.title}</p>
                                <p>￥{item.price}元</p>
                            </div>
                            <div
                                className="add"
                                onClick={() => {
                                    this.props.addCart(item);
                                }}
                            >
                                +
                            </div>
                        </div>
                    );
                })}
            </div>
        );
    }
}

export default connect(
    state => {
        return {};
    },
    dispatch => {
        return {
            addCart(item) {
                dispatch(add_cart_action(item));
            }
        };
    }
)(DetList);
